<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">

    <link rel="stylesheet" href="../bootstrap-3.3.4/dist/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="../Flat-UI-master/dist/css/flat-ui.min.css"/>
    <script src="../Flat-UI-master/dist/js/vendor/jquery.min.js"></script>
    <script src="../bootstrap-3.3.4/dist/js/bootstrap.min.js"></script>
    <script src="../Flat-UI-master/dist/js/flat-ui.min.js"></script>
    <title></title>
    <style>
        .row{
            margin-left: 20px;
            margin-right: 20px;;
        }
        .line-center{
            line-height:50px;
            text-align: center;
        }
        .row input{
            width: 50px;
        }
        .list-group-item:hover{
            background: #27ae60;

        }
        .list-group-item div:first-child:hover{

            cursor: pointer;
        }
    </style>
    <script>
        function myClick(n){
           location.href = "OrderInfo.html";
        }
        function btnClick(){
            alert("btn");
            return false;
        }
        $(function(){

        })
    </script>
    <script src="../js/jquery-3.2.1.min.js"></script>
</head>
<body>
<!-- Static navbar -->
<div class="navbar navbar-default navbar-static-top" role="navigation">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="sr-only">这什么东西</span>
            </button>
            <a class="navbar-brand" href="Index.html">图书商城</a>
        </div>
        <div class="navbar-collapse collapse">
            <ul class="nav navbar-nav">
                <li class="active"><a href="Index.html">首页</a></li>
                <li><a href="Order.html">我的订单</a></li>
                <li><a href="UserInfo.html">个人中心</a></li>
                <li hidden><a href="FriendLink.html">友情链接</a></li>
            </ul>
            <ul class="nav navbar-nav navbar-right hidden-sm">
                <li><a href="Login.html">登录</a></li>
                <li><a href="Register.html">注册</a></li>
                <li><a id="out">退出</a></li>
                <li>
                    <a href="Cart.html"><span class="glyphicon glyphicon-shopping-cart">购物车</span></a></li>
            </ul>
        </div><!--/.nav-collapse -->
    </div>
</div>
<!--content-->
<div class="container">
    <div class="row thumbnail center">
        <div class="col-sm-12">
            <h1 class="text-center" style="margin-bottom: 30px">我的订单</h1>
        </div>
        <div class="col-sm-12 thumbnail">
            <div class="col-sm-3 line-center">订单编号</div>
            <div class="col-sm-2 line-center">订单状态</div>
            <div class="col-sm-2 line-center">商品数量 </div>
            <div class="col-sm-2 line-center">订单总价</div>
            <div class="col-sm-3 line-center">操作</div>
        </div>
        <div class="list-group">
            <!--<div class="col-sm-12  list-group-item" >-->
                <!--<div class="col-sm-3 line-center" onclick="myClick(1)">ahiudsfhjk-23423-23asd-12</div>-->
                <!--<div class="col-sm-2 line-center">未付款</div>-->
                <!--<div class="col-sm-2 line-center">12 </div>-->
                <!--<div class="col-sm-2 line-center">1231.00元</div>-->
                <!--<div class="col-sm-3 line-center">-->
                    <!--<button class="btn btn-danger">删除订单</button>-->
                    <!--<button class="btn btn-success">提交订单</button>-->

                <!--</div>-->
            <!--</div>-->
    </div>
</div>


<!--footer-->
<div class="navbar navbar-default navbar-static-bottom">
    版权声明区
</div>
    <script>
        window.onload=function () {
            $.ajax({
                url:"/orders",
                type:"get",
                success:function (re) {
                    console.log(re);
                    if (re.code == 1000) {
                    for (var i = 0; i < re.data.length; i++) {
                        if (re.data[i].state!=1) {
                            $("<div class=\"col-sm-12  list-group-item\" id='div'>\n" +
                                "                <div class=\"col-sm-3 line-center\" id='orderitem' \">" + re.data[i].oid + "</div>\n" +
                                "                <div class=\"col-sm-2 line-center\">" + re.data[i].stringstate + "</div>\n" +
                                "                <div class=\"col-sm-2 line-center\">" + re.data[i].orderscount + "</div>\n" +
                                "                <div class=\"col-sm-2 line-center\">" + re.data[i].total + "元</div>\n" +
                                "                <div class=\"col-sm-3 line-center\">\n" +
                                "                    <button class=\"btn btn-danger\" id='del' name='\"+re.data[i].oid+\"'>删除订单</button>\n" +
                                "                </div>\n" +
                                "            </div>").appendTo(".list-group");
                        }else {
                            $("<div class=\"col-sm-12  list-group-item\" >\n" +
                                "                <div class=\"col-sm-3 line-center\" id='orderitem' \">" + re.data[i].oid + "</div>\n" +
                                "                <div class=\"col-sm-2 line-center\" id='state'>" + re.data[i].stringstate + "</div>\n" +
                                "                <div class=\"col-sm-2 line-center\">" + re.data[i].orderscount + "</div>\n" +
                                "                <div class=\"col-sm-2 line-center\">" + re.data[i].total + "元</div>\n" +
                                "                <div class=\"col-sm-3 line-center\">\n" +
                                "                    <button class=\"btn btn-danger\" id='del' name='"+re.data[i].oid+"'>删除订单</button>\n" +
                                "                    <button class=\"btn btn-success\" id='pay' name='" + re.data[i].oid + "'>提交订单</button>\n" +
                                "\n" +
                                "                </div>\n" +
                                "            </div>").appendTo(".list-group");
                        }
                    }
                   }else if (re.code == 1001) {
                        console.log(re.msg)
                    }else if (re.code == 1003) {
                        console.log(re.msg)
                        location.href="/Home/Login.html";
                    }
                }
            })
        }
        $(".list-group").on("click","#pay",function () {
            var a=$(this);
            var oid = $(this).attr("name");
            $.ajax({
                url:"/buyorders",
                type:"get",
                data:{
                    oid:oid,
                    newstate:2
                },
                success:function (re) {
                    if (re.code == 1003) {
                        location.href="/Home/Login.html";
                    }else if (re.code == 1001) {
                        console.log("修改失败")
                    }else if (re.code == 1000) {
                        a.parents().parents(".col-sm-12").children("#state").html("已付款未发货");
                        a.remove();
                    }
                }
            })
        });
        $(".list-group").on("click","#del",function () {
            var a = $(this)
            var oid = $(this).attr("name");
            $.ajax({
                url:"/delorders",
                type:"get",
                data:{
                    oid:oid
                },
                success:function (re) {
                    if (re.code == 1000) {
                        console.log(a.parents().parents(".col-sm-12"));
                        a.parents().parents(".col-sm-12").remove();
                    }else if (re.code == 1001) {
                        console.log("删除失败")
                    }else if (re.code == 1003) {
                        location.href="/Home/Login.html";
                    }
                }
            })
        });
        // $("#orderitem").click(function () {
        //     var oid = $(this).html();
        //     location.href="/Home/OrderInfo.html?oid="+oid;
        // })
        $(".list-group").on("click","#orderitem",function () {
            var oid = $(this).html();
            location.href="/Home/OrderInfo.html?oid="+oid;
        })
        $("#out").click(function () {
            $.ajax({
                url:"/out",
                type:"get",
                success:function (re) {
                    if (re.code == 1000) {
                        location.href="/Home/Login.html"
                    }
                }
            })
        })
    </script>
</body>
</html>